{extend name="Layout/index" /}

{block name="main"}
<div style="margin: 15px;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>添加权限</legend>
    </fieldset>

    <form class="layui-form" action="{:url('permission/store')}" method="POST">
        <div class="layui-form-item">
            <label class="layui-form-label">名字(路由)</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="title" autocomplete="off"   class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <input type="text" name="description" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">选择权限组</label>
            <div class="layui-input-block">
                <select name="parent_id" lay-verify="parent_id">
                    <option value="0">父级</option>
                    {foreach $permissionList as $key=>$vo }
                        <option value="{$vo.id}">{$vo.description}</option>
                        {if $vo->child}
                            {foreach($vo['child'] as $cv)}
                                <option {$cv->id == $parent_id ? 'selected' : ''}
                                    value="{$cv->id}">
                                    |--- {$cv->description}
                                </option>
                            {/foreach}
                        {/if}
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">图标</label>
            <div class="layui-input-inline">
                <input type="text" name="icon" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-inline">
                <input type="text" name="sort_order" class="layui-input" value="0">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">显示菜单</label>
            <div class="layui-input-block">
                <input type="checkbox" name="display_menu" lay-skin="switch" lay-text="ON|OFF">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">新增</button>
                <a href="{:url('permission/index')}" class="layui-btn layui-btn-primary">返回</a>
            </div>
        </div>
    </form>
</div>
{/block}

{block name="footer"}
<script>
    layui.use(['form', 'layedit', 'laydate'], function() {
        var form = layui.form;

        //自定义验证规则
        form.verify({
            title: function(value) {
                if(value.length < 1) {
                    return '权限名不能为空';
                }
            },
            parent_id: function(value) {
                if(value < 0) {
                    return '请选择权限组';
                }
            }
        });

    });
</script>
{/block}